﻿using EFCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SIService;
using SService;

namespace WMSWeb.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CustomermanagementController : ControllerBase
    {
        private readonly WmssystemContext myDb;
        private readonly CustomermanagementS customermanagementS;

        public CustomermanagementController(WmssystemContext myDb, SService.CustomermanagementS customermanagementS)
        {
            this.myDb = myDb;
            this.customermanagementS = customermanagementS;
        }

        /// <summary>
        /// 查询全部客户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<List<Su_Customermanagement>> Qu()
        {
            return customermanagementS.Qu();
        }
        /// <summary>
        /// 根据客户名称查询联系人和联系电话
        /// </summary>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<Su_Customermanagement> QuName(int Name)
        {
            return await customermanagementS.QuName(Name);
        }
        /// <summary>
        /// 客户分页模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("FenYe")]
        public async Task<List<Su_Customermanagement>> FenYe(int pageSize, int currentPage, string Key = null, string Status = null, string Industry = null, string Person = null)
        {
            return await customermanagementS.FenYe(pageSize, currentPage, Key, Status, Industry, Person);
        }
        /// <summary>
        /// 客户添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<int>> Add(Su_Customermanagement cusAdd)
        {
            // 为实体的属性赋值
            cusAdd.S_CuOperatorTime = DateTime.Now;
            cusAdd.S_CuOperator = "张三";
            cusAdd.S_CuisDelete = true;

            // 调用服务层的方法执行添加操作
            return await customermanagementS.Add(cusAdd);
        }
        /// <summary>
        /// 客户修改
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<ActionResult<int>> Update(Su_Customermanagement cusUpd)
        {
            return await customermanagementS.Upd(cusUpd);
        }
        /// <summary>
        /// 客户逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdIsDelete")]
        public async Task<ActionResult<int>> UpdIsDelete(int id, bool isDeleted)
        {
            return await customermanagementS.UpdIsDelete(id, isDeleted);
        }



    }
}
